﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using MicroDal;

namespace MicroDalTests
{
    [TestClass]
    public class SqlBuilderTest
    {
        [TestMethod]
        public void SimpelSelect()
        {
            var exp = "SELECT * FROM TestDto";
            var b = new SqlBuilder(typeof(TestDto));
            var sql = b.SelectAll();

            Assert.AreEqual(exp, sql);
        }

        [TestMethod]
        public void SimpelColumnSelect()
        {
            var exp = "SELECT TOP 10 Id, Dob FROM TestDto";
            var b = new SqlBuilder(typeof(TestDto));
            var sql = b.Select(columns: "Id, Dob", limit: 10);

            Assert.AreEqual(exp, sql);
        }

        [TestMethod]
        public void SimpelSelectWithLimit()
        {
            var exp = "SELECT TOP 101 * FROM TestDto";
            var b = new SqlBuilder(typeof(TestDto));
            var sql = b.SelectAll(limit: 101);

            Assert.AreEqual(exp, sql);
        }

        [TestMethod]
        public void SimpelSelectWithLimitAndOrder()
        {
            var exp = "SELECT TOP 101 * FROM TestDto ORDER BY Dob";
            var b = new SqlBuilder(typeof(TestDto));
            var sql = b.SelectAll(orderBy: "Dob", limit: 101);

            Assert.AreEqual(exp, sql);
        }

        [TestMethod]
        public void SimpelSelectWithWhere()
        {
            var exp = "SELECT * FROM TestDto WHERE Id=1";
            var b = new SqlBuilder(typeof(TestDto));
            var sql = b.SelectAll(where: "Id=1");

            Assert.AreEqual(exp, sql);
        }

        [TestMethod]
        public void SimpelSelectWithLimitAndWhere()
        {
            var exp = "SELECT TOP 101 * FROM TestDto WHERE Id=2";
            var b = new SqlBuilder(typeof(TestDto));
            var sql = b.SelectAll(where: "Id=2", limit: 101);

            Assert.AreEqual(exp, sql);
        }
    }

    public class TestDto
    {
        public int Id { get; set; }
        public string Name { get; set; }
        public DateTime Dob { get; set; }
    }
}
